package com.bizfx.component.controls
{
	import flash.events.MouseEvent;
	
	import mx.containers.Box;
	import mx.containers.BoxDirection;
	import mx.containers.DividedBox;
	import mx.controls.Button;
	import mx.controls.Image;
	import mx.core.mx_internal;
	
	use namespace mx_internal;
	
	public class DividerBox extends Button
	{
		[Embed(source='/assets/images/resultset_previous.png')]
		public static const DividerIcon_left:Class;  
		
		[Embed(source='/assets/images/resultset_next.png')]
		public static const DividerIcon_right:Class;  
		
		private var image:Image = new Image();
		private var isOpened:Boolean = true;
		private var dividbox:DividedBox = null;
		
		public function DividerBox()
		{
			super();
		}
		
		override protected function createChildren():void {
			super.createChildren();
			this.dividbox = this.parent.parent.parent as DividedBox;
			this.setStyle("cornerRadius", 0);
			this.image.width = 10;
			this.image.height = 10;
			this.image.source = DividerIcon_left;
			this.addChild(image);			
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			if (this.dividbox.direction == BoxDirection.HORIZONTAL) {
				this.width = 10;
				this.height = 70;
			} else {
				this.width = 70;
				this.height = 10;
			}
		}
		
		private function mouseClickHandler(event:MouseEvent):void{
			if(isOpened){
				image.source = DividerIcon_right;
				dividbox.getChildAt(0).width = 0;
				isOpened = false;
			}else{
				isOpened = true;
				image.source = DividerIcon_left;
				dividbox.getChildAt(0).width = 180;
			}
		}
	}
}